package metalink.admin;

import java.util.ArrayList;
import java.util.Vector;

import model.admin.GetBatchListMo;
import model.admin.GetCourseListMo;
import model.admin.ModifyDepartmentsMo;

import vo.BatchDetailsVo;
import vo.mixed.CourseListVo;
import vo.mixed.DegreeListVo;
import vo.mixed.DepartmentListVo;
import vo.mixed.ProfessorListVo;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class GetDepartmentList extends ActionSupport {
	int department_id;
	int professor_id;
	ArrayList<DepartmentListVo> department_list;
	ArrayList<CourseListVo> department_course_list;
	ArrayList<ProfessorListVo> department_course_professor_list;
	
	ArrayList<DegreeListVo> degreeList = new ArrayList<DegreeListVo>();
	ArrayList<DegreeListVo> degree = new ArrayList<DegreeListVo>();
	ArrayList<BatchDetailsVo> batchlist = new ArrayList<BatchDetailsVo>();
	ArrayList<BatchDetailsVo> batch = new ArrayList<BatchDetailsVo>();
	ArrayList<ProfessorListVo> prof = new ArrayList<ProfessorListVo>();
	String value="";
	int course_id;
	int degree_id;
	int batch_id;
	int staff_id;

	private int result;

	//------------ Pagination --------------//
	private int page;
	private String morepages;
	private Vector noofpages=new Vector();
	private int nextpage;
	private int currentpage;
	private String hasprevpage;
	private int prevpage;
	private int items;
	//private Vector pagelist=new Vector();
	//private ArrayList<DepartmentListVo> pagelist;
	
	public int getProfessor_id() {
		return professor_id;
	}

	public void setProfessor_id(int professor_id) {
		this.professor_id = professor_id;
	}

	public ArrayList<ProfessorListVo> getDepartment_course_professor_list() {
		return department_course_professor_list;
	}

	public void setDepartment_course_professor_list(
			ArrayList<ProfessorListVo> department_course_professor_list) {
		this.department_course_professor_list = department_course_professor_list;
	}

	public ArrayList<CourseListVo> getDepartment_course_list() {
		return department_course_list;
	}

	public void setDepartment_course_list(
			ArrayList<CourseListVo> department_course_list) {
		this.department_course_list = department_course_list;
	}

	public ArrayList<DepartmentListVo> getDepartment_list() {
		return department_list;
	}

	public void setDepartment_list(ArrayList<DepartmentListVo> department_list) {
		this.department_list = department_list;
	}

	public int getDepartment_id() {
		return department_id;
	}

	public void setDepartment_id(int department_id) {
		this.department_id = department_id;
	}

	public int getCourse_id() {
		return professor_id;
	}

	public void setCourse_id(int course_id) {
		this.professor_id = course_id;
	}
	
	public String execute() throws Exception {
		GetBatchListMo department_obj = new GetBatchListMo();
		GetCourseListMo coursemo =new GetCourseListMo();
		ModifyDepartmentsMo modify= new ModifyDepartmentsMo();
		ModifyDepartmentsMo modifydep = new ModifyDepartmentsMo();
		if(value.contentEquals("viewprof")){
			ArrayList<ProfessorListVo> pagelist = new ArrayList<ProfessorListVo>();
			prof = coursemo.getDepartmentProfeesor(department_id);
			department_course_professor_list=coursemo.getCourseProfessorDetails(course_id, department_id);
			result = prof.size();
			//---------- Pagination ------------------//
			
			int p=getPage();
	        if(p==0)
	        {
	            setHasprevpage("false");
	        }
	        else
	        {
	            setHasprevpage("true");
	            setPrevpage(p-1);
	        }

	        setCurrentpage(p);

	        int count;
	        count=0;

	        int size=prof.size();
	        setItems(size);
	        int pagesinlist=size/15;
	        while(count<=pagesinlist)
	        {
	            noofpages.add(count);
	            count++;
	        }
	        count=0;
	        while(count<15)
	        {

	            if(size>=(p*15)+count+1)
	            {
	                System.out.println(p);
	                pagelist.add(prof.get((p*15)+count));
	                System.out.println((p*15)+count);
	                System.out.println("size"+pagelist.size());
	                count++;
	                setMorepages("true");
	                setNextpage(p+1);

	            }
	            else
	            {
	                setMorepages("false");
	                break;
	            }
	        }
		}else if(value.contentEquals("viewdeg")){
			ArrayList<DegreeListVo> pagelist = new ArrayList<DegreeListVo>();
			degreeList=department_obj.getDepartmentDegreeList(department_id);
			degree=department_obj.getAddDepartmentDegree(department_id);
			result = degreeList.size();
			//---------- Pagination ------------------//
			
			int p=getPage();
	        if(p==0)
	        {
	            setHasprevpage("false");
	        }
	        else
	        {
	            setHasprevpage("true");
	            setPrevpage(p-1);
	        }

	        setCurrentpage(p);

	        int count;
	        count=0;

	        int size=degreeList.size();
	        setItems(size);
	        int pagesinlist=size/15;
	        while(count<=pagesinlist)
	        {
	            noofpages.add(count);
	            count++;
	        }
	        count=0;
	        while(count<15)
	        {

	            if(size>=(p*15)+count+1)
	            {
	                System.out.println(p);
	                pagelist.add(degreeList.get((p*15)+count));
	                System.out.println((p*15)+count);
	                System.out.println("size"+pagelist.size());
	                count++;
	                setMorepages("true");
	                setNextpage(p+1);

	            }
	            else
	            {
	                setMorepages("false");
	                break;
	            }
	        }
		}else if(value.contentEquals("viewbatch")){
			ArrayList<BatchDetailsVo> pagelist = new ArrayList<BatchDetailsVo>();
			batch=department_obj.getAddDepartmentBatch(department_id);
			batchlist = department_obj.getDepartmentBatchList(department_id);
			result = batchlist.size();
			//---------- Pagination ------------------//
			
			int p=getPage();
	        if(p==0)
	        {
	            setHasprevpage("false");
	        }
	        else
	        {
	            setHasprevpage("true");
	            setPrevpage(p-1);
	        }

	        setCurrentpage(p);

	        int count;
	        count=0;

	        int size=batchlist.size();
	        setItems(size);
	        int pagesinlist=size/15;
	        while(count<=pagesinlist)
	        {
	            noofpages.add(count);
	            count++;
	        }
	        count=0;
	        while(count<15)
	        {

	            if(size>=(p*15)+count+1)
	            {
	                System.out.println(p);
	                pagelist.add(batchlist.get((p*15)+count));
	                System.out.println((p*15)+count);
	                System.out.println("size"+pagelist.size());
	                count++;
	                setMorepages("true");
	                setNextpage(p+1);

	            }
	            else
	            {
	                setMorepages("false");
	                break;
	            }
	        }
		}else if (value.contentEquals("updatedepdeg")){
			ArrayList<DegreeListVo> pagelist = new ArrayList<DegreeListVo>();
			modifydep.updateDepartmentDegree(department_id, degree_id,value);
			degreeList=department_obj.getDepartmentDegreeList(department_id);
			degree=department_obj.getAddDepartmentDegree(department_id);
			result = degreeList.size();
			//---------- Pagination ------------------//
			
			int p=getPage();
	        if(p==0)
	        {
	            setHasprevpage("false");
	        }
	        else
	        {
	            setHasprevpage("true");
	            setPrevpage(p-1);
	        }

	        setCurrentpage(p);

	        int count;
	        count=0;

	        int size=degreeList.size();
	        setItems(size);
	        int pagesinlist=size/15;
	        while(count<=pagesinlist)
	        {
	            noofpages.add(count);
	            count++;
	        }
	        count=0;
	        while(count<15)
	        {

	            if(size>=(p*15)+count+1)
	            {
	                System.out.println(p);
	                pagelist.add(degreeList.get((p*15)+count));
	                System.out.println((p*15)+count);
	                System.out.println("size"+pagelist.size());
	                count++;
	                setMorepages("true");
	                setNextpage(p+1);

	            }
	            else
	            {
	                setMorepages("false");
	                break;
	            }
	        }
		}else if (value.contentEquals("updatedepbatch")){
			ArrayList<BatchDetailsVo> pagelist = new ArrayList<BatchDetailsVo>();
			modifydep.updateDepartmentBatch(department_id, batch_id,value);
			batch=department_obj.getAddDepartmentBatch(department_id);
			batchlist = department_obj.getDepartmentBatchList(department_id);
			result = batchlist.size();
			//---------- Pagination ------------------//
			
			int p=getPage();
	        if(p==0)
	        {
	            setHasprevpage("false");
	        }
	        else
	        {
	            setHasprevpage("true");
	            setPrevpage(p-1);
	        }

	        setCurrentpage(p);

	        int count;
	        count=0;

	        int size=batchlist.size();
	        setItems(size);
	        int pagesinlist=size/15;
	        while(count<=pagesinlist)
	        {
	            noofpages.add(count);
	            count++;
	        }
	        count=0;
	        while(count<15)
	        {

	            if(size>=(p*15)+count+1)
	            {
	                System.out.println(p);
	                pagelist.add(batchlist.get((p*15)+count));
	                System.out.println((p*15)+count);
	                System.out.println("size"+pagelist.size());
	                count++;
	                setMorepages("true");
	                setNextpage(p+1);

	            }
	            else
	            {
	                setMorepages("false");
	                break;
	            }
	        }
		}else if(value.contentEquals("updatedestaff")){
			ArrayList<ProfessorListVo> pagelist = new ArrayList<ProfessorListVo>();
			modify.updateDepartmentProfessor(department_id, staff_id,value);
			prof = coursemo.getDepartmentProfeesor(department_id);
			department_course_professor_list=coursemo.getCourseProfessorDetails(course_id, department_id);
			result = department_course_professor_list.size();
			//---------- Pagination ------------------//
			
			int p=getPage();
	        if(p==0)
	        {
	            setHasprevpage("false");
	        }
	        else
	        {
	            setHasprevpage("true");
	            setPrevpage(p-1);
	        }

	        setCurrentpage(p);

	        int count;
	        count=0;

	        int size=department_course_professor_list.size();
	        setItems(size);
	        int pagesinlist=size/15;
	        while(count<=pagesinlist)
	        {
	            noofpages.add(count);
	            count++;
	        }
	        count=0;
	        while(count<15)
	        {

	            if(size>=(p*15)+count+1)
	            {
	                System.out.println(p);
	                pagelist.add(department_course_professor_list.get((p*15)+count));
	                System.out.println((p*15)+count);
	                System.out.println("size"+pagelist.size());
	                count++;
	                setMorepages("true");
	                setNextpage(p+1);

	            }
	            else
	            {
	                setMorepages("false");
	                break;
	            }
	        }
		
		}
		else if (value.contentEquals("deleteprof")){
			ArrayList<ProfessorListVo> pagelist = new ArrayList<ProfessorListVo>();
			coursemo.deleteDepartmentProfessor(department_id, staff_id, value);
			prof = coursemo.getDepartmentProfeesor(department_id);
			department_course_professor_list=coursemo.getCourseProfessorDetails(course_id, department_id);
			result = department_course_professor_list.size();
			//---------- Pagination ------------------//
			
			int p=getPage();
	        if(p==0)
	        {
	            setHasprevpage("false");
	        }
	        else
	        {
	            setHasprevpage("true");
	            setPrevpage(p-1);
	        }

	        setCurrentpage(p);

	        int count;
	        count=0;

	        int size=department_course_professor_list.size();
	        setItems(size);
	        int pagesinlist=size/15;
	        while(count<=pagesinlist)
	        {
	            noofpages.add(count);
	            count++;
	        }
	        count=0;
	        while(count<15)
	        {

	            if(size>=(p*15)+count+1)
	            {
	                System.out.println(p);
	                pagelist.add(department_course_professor_list.get((p*15)+count));
	                System.out.println((p*15)+count);
	                System.out.println("size"+pagelist.size());
	                count++;
	                setMorepages("true");
	                setNextpage(p+1);

	            }
	            else
	            {
	                setMorepages("false");
	                break;
	            }
	        }
		}
		else{
		setDepartment_list(department_obj.getDepartmentList(0, 0,0));
		}
		return SUCCESS;
	}
	
	
/*
	public String execute() throws Exception {
		GetBatchListMo department_obj = new GetBatchListMo();
		setDepartment_list(department_obj.getDepartmentList(0, 0));
		
		pagelist = new ArrayList<DepartmentListVo>();
		result = department_list.size();
				
				//---------- Pagination ------------------//
				
				int p=getPage();
		        if(p==0)
		        {
		            setHasprevpage("false");
		        }
		        else
		        {
		            setHasprevpage("true");
		            setPrevpage(p-1);
		        }

		        setCurrentpage(p);

		        int count;
		        count=0;

		        int size=department_list.size();
		        setItems(size);
		        int pagesinlist=size/15;
		        while(count<=pagesinlist)
		        {
		            noofpages.add(count);
		            count++;
		        }
		        count=0;
		        while(count<15)
		        {

		            if(size>=(p*15)+count+1)
		            {
		                System.out.println(p);
		                pagelist.add(department_list.get((p*15)+count));
		                System.out.println((p*15)+count);
		                System.out.println("size"+pagelist.size());
		                count++;
		                setMorepages("true");
		                setNextpage(p+1);

		            }
		            else
		            {
		                setMorepages("false");
		                break;
		            }
		        }
		
		
		return SUCCESS;
	}

	public String getDepartmentCourseDetails() throws Exception {
		GetBatchListMo dept_course_obj = new GetBatchListMo();
		setDepartment_course_list(dept_course_obj.getBatchCourseList(0,
				department_id));
		return SUCCESS;
	}
public String getDepartmentCourseProfessorDetails(){
	GetCourseListMo dept_course_prof_obj = new GetCourseListMo();
setDepartment_course_professor_list(dept_course_prof_obj.getCourseList(professor_id));
	return SUCCESS;
}
*/
public int getResult() {
	return result;
}

public void setResult(int result) {
	this.result = result;
}

public int getPage() {
	return page;
}

public void setPage(int page) {
	this.page = page;
}

public String getMorepages() {
	return morepages;
}

public void setMorepages(String morepages) {
	this.morepages = morepages;
}

public Vector getNoofpages() {
	return noofpages;
}

public void setNoofpages(Vector noofpages) {
	this.noofpages = noofpages;
}

public int getNextpage() {
	return nextpage;
}

public void setNextpage(int nextpage) {
	this.nextpage = nextpage;
}

public int getCurrentpage() {
	return currentpage;
}

public void setCurrentpage(int currentpage) {
	this.currentpage = currentpage;
}

public String getHasprevpage() {
	return hasprevpage;
}

public void setHasprevpage(String hasprevpage) {
	this.hasprevpage = hasprevpage;
}

public int getPrevpage() {
	return prevpage;
}

public void setPrevpage(int prevpage) {
	this.prevpage = prevpage;
}

public int getItems() {
	return items;
}

public void setItems(int items) {
	this.items = items;
}
/*
public ArrayList<DepartmentListVo> getPagelist() {
	return pagelist;
}

public void setPagelist(ArrayList<DepartmentListVo> pagelist) {
	this.pagelist = pagelist;
}
*/
public ArrayList<DegreeListVo> getDegreeList() {
	return degreeList;
}

public void setDegreeList(ArrayList<DegreeListVo> degreeList) {
	this.degreeList = degreeList;
}

public ArrayList<DegreeListVo> getDegree() {
	return degree;
}

public void setDegree(ArrayList<DegreeListVo> degree) {
	this.degree = degree;
}

public ArrayList<BatchDetailsVo> getBatchlist() {
	return batchlist;
}

public void setBatchlist(ArrayList<BatchDetailsVo> batchlist) {
	this.batchlist = batchlist;
}

public ArrayList<BatchDetailsVo> getBatch() {
	return batch;
}

public void setBatch(ArrayList<BatchDetailsVo> batch) {
	this.batch = batch;
}

public ArrayList<ProfessorListVo> getProf() {
	return prof;
}

public void setProf(ArrayList<ProfessorListVo> prof) {
	this.prof = prof;
}

public String getValue() {
	return value;
}

public void setValue(String value) {
	this.value = value;
}

public int getDegree_id() {
	return degree_id;
}

public void setDegree_id(int degree_id) {
	this.degree_id = degree_id;
}

public int getBatch_id() {
	return batch_id;
}

public void setBatch_id(int batch_id) {
	this.batch_id = batch_id;
}

public int getStaff_id() {
	return staff_id;
}

public void setStaff_id(int staff_id) {
	this.staff_id = staff_id;
}
}
